********************************************************************************
* Exporting table for multi-country COVID paper (NPL1 sample)
* last updated: 2020-10-12
* Corey Vernot, Salim Benhachmi
********************************************************************************

* 1. Cleaning Data

clear all
use "$da/NPL1_HH", clear
tempfile hh
save `hh'

keep hhid today round
merge 1:m hhid today using "$da/NPL1_IND", force nogen

gen wagebus = wage + bus > 0 if !mi(wage) & !mi(bus) //any wage or n.f. business work last two weeks

collapse (max) employed = wagebus , by(hhid today round base_inc) //aggregate ind. employment to hh level

merge 1:1 hhid today using `hh', nogen
bysort hhid round (today): keep if _n == _N //Keep only first observation for each round
bysort hhid (round): keep if _N == 2 //Keep only households with pre and post observations

keep hhid round laborInc_hh

reshape wide laborInc_hh , i(hhid) j(round)

rename (laborInc_hh3 laborInc_hh6) (pre_inc post_inc)

gen drop_inc = (post_inc < pre_inc) if post_inc != . & pre_inc != .
gen incr_inc = (post_inc > pre_inc) if post_inc != . & pre_inc != .

********************************************************************************

* 2. Output

local indicators drop_inc incr_inc

foreach ind of local indicators {
	sum `ind'
	loc mean_`ind' : di %10.2fc r(mean)
}

loc ratio = round(`mean_drop_inc' / `mean_incr_inc', 0.1)

clear
set obs 1

gen drop_inc = "`mean_drop_inc'"
gen incr_inc = "`mean_incr_inc'"
gen ratio = "`ratio'"

export excel using "$dtab/Inverse Table.xlsx", sheetmodify cell(B22)

********************************************************************************
